#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<iostream>
#include<Windows.h>

#include<mmsystem.h>
#pragma comment(lib,"winmm.lib")

#define IMAGECOUNTS  147
#define IM_ROW 61
#define IM_COL 81

char map[IMAGECOUNTS][IM_ROW][IM_COL+1];//图片

void init()
{
	//控制台标题
	SetConsoleTitle("极乐净土");
	//控制台大小 分辨率
	system("mode con cols=80 lines=61");

	//隐藏光标操作 
	HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO info = { 1,0 };
	SetConsoleCursorInfo(hOutput, &info);

}
void readData()
{
	FILE* fp = NULL;
	char fname[150] = { 0 };
	for (int i = 0; i < IMAGECOUNTS; i++)
	{
		int row = 0;
		sprintf(fname, "D:\\1.编程代码\\fascinating\\控制台极乐净土\\控制台极乐净土\\images1/ASCII-_%04d_图层-%d.txt", i, 148 - i);
		//%04d有4位不足的补0
		//sprintf：写到字符串中，sscanf：将字符串写到内存中
		fp = fopen(fname, "r");
		if (fp == NULL)
		{
			printf("%d\n", i);
			perror("fopen");
			exit(-1);
		}
		for ( row = 0;  row < IM_ROW;  row++)
		{
			fgets(map[i][row], sizeof(map[i][row]), fp);
		    //fgets会读取到'\n'
			map[i][row][IM_COL] = '\0';
			row++;
		}
		fclose(fp);
	}
}
void play()
{
	system("cls");
	for (int i = 0; i < IMAGECOUNTS; i++)
	{
		for (int j = 0; j < IM_ROW; j++)
		{
			printf("%s", map[i][j]);
		}
		system("3");
		//打完一个文件光标需要回到最上面
		HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
		COORD loc;
		loc.X = 0;
		loc.Y = 0;
		SetConsoleCursorPosition(hOutput, loc);

		//隐藏光标操作 
		CONSOLE_CURSOR_INFO info = { 1,0 };
		SetConsoleCursorInfo(hOutput, &info);
	}
}

int main()
{
	init();
	readData();
	while (1)
	{
		mciSendString("open ./bg.mp3", 0, 0, 0);
		mciSendString("play ./bg.mp3", 0, 0, 0);
		play();
	}
	return 0;
}